//
//  ViewController.m
//  27-ArrayDataSource
//
//  Created by dllo on 16/8/19.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"
#define kTableViewReuse @"reuse"
#import "ArrayDataSource.h"
@interface ViewController ()<UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *nameArr;
@property (nonatomic, strong) ArrayDataSource *arratDataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _nameArr = [NSArray array];
    [self handleData];
    [self createTableView];
}
- (void)handleData {
     _nameArr = @[ @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪", @"赵五一"];
}
- (void)createTableView {
    // ArrayDataSource, 让其替代ViewController的数据源工作
    self.arratDataSource = [ArrayDataSource arrayDataSourceWithTableViewCellReuse:kTableViewReuse arrayDataSource:_nameArr configCell:^(UITableViewCell * _Nonnull cell, id  _Nonnull model) {
        cell.textLabel.text = model;
    }];
    _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewReuse];
    _tableView.delegate = self;
    // tableView的数据源变更为自定义的类
    // 注意: 所有的协议不一定只能指向self
    _tableView.dataSource = _arratDataSource;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
